﻿@using ZoomLa.Model
@using System.Data
@using ZoomLa.Common
@using ZoomLa.SQLDAL
@using Newtonsoft.Json
@model ZoomLa.Model.Shop.M_Order_Repair
@functions{
    //退货数量必须是该值的倍数
    public int GetBackMulti(int cartID)
    {
        int result = 1;
        DataTable ptDT = DBCenter.Sel("ZL_Cart_Present", "CartID=" + cartID);
        if (ptDT.Rows.Count < 1) { return result; }
        //以值大的为准
        foreach (DataRow dr in ptDT.Rows)
        {
            int num = DataConvert.CLng(dr["W_StartNum"]);
            if (num > result) { result = num; }
        }
        return result;
    }
}
@{

    string takedate = (DateTime.Now.Hour > 19 ? DateTime.Now.AddDays(1) : DateTime.Now).ToString("yyyy-MM-dd  15:00-19:00");
    M_CartPro cartMod = ViewBag.cartMod;
    M_Product proMod = ViewBag.proMod;
    M_OrderList orderMod = ViewBag.orderMod;
    int proMulti = GetBackMulti(cartMod.ID);
}
@section head{
<title>申请返修</title>
<style>
    body { font-family: "Microsoft Yahei", SimSun, Tahoma, Helvetica, Arial, sans-serif; height: 100%; }
    .reqrepair .line30 { line-height: 30px; }
    .typesel_div .active_div { border: 2px solid red !important; }
    .reqrepair .type_div { float: left; margin-right: 10px; border: 1px solid #ddd; padding: 0 10px; cursor: pointer; }
    .reqrepair .row { margin-top: 10px; }
    .reqrepair .tip_div { color: #999; }
    .reqrepair .protable td { text-align: center; }
    .protable .title_td { text-align: left; }
    .reqrepair .proinfo_td div { padding: 5px; }
</style>
<script src="/JS/ICMS/area.js"></script>
<script src="/JS/Controls/ZL_PCC.js"></script>
}
@section content{
<div id="pageflag" data-nav="shop" data-ban="shop"></div>
<div class="container margin_t5">
    <ol class="breadcrumb">
        <li><a title="会员中心" href="/User/Default">会员中心</a></li>
        <li class="active">申请返修</li>
    </ol>
</div>
<form method="post" action="@MVCHelper.GetAction("ReqRepair_Add",Request)">
    <div class="container reqrepair">
        <table class="table table-striped protable">
            <tr style="background-color:#f5f5f5;">
                <td>商品名称</td>
                <td>购买数量</td>
                <td>商品单价</td>
                <td>购买时间</td>
            </tr>
            <tr>
                <td class="proinfo_td">
                    <div class="col-md-2"><img src="@function.GetImgUrl(proMod.Thumbnails)" onerror="shownopic(this);" id="ProImgSrc" style="width:100%;height:80px;" /></div>
                    <div class="col-md-10 title_td">
                        @cartMod.Proname
                        @Html.Partial("OrderList_Present",(DataRow)ViewBag.cartDR)
                    </div>
                </td>
                <td>@cartMod.Pronum</td>
                <td>￥@cartMod.Shijia</td>
                <td>@cartMod.Addtime</td>
            </tr>
        </table>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">申请返修</h3>
            </div>
            <div class="panel-body">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>服务类型：</div>
                        <div class="col-md-10 line30 typesel_div">
                            @MvcHtmlString.Create(ViewBag.ServiceType)
                            <input type="hidden" id="ServicesType_Hid" name="ServicesType_Hid" value="@Model.ServiceType" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>提交数量：</div>
                        <div class="col-md-10 line30">
                            <input type="text" id="ProNum" name="ProNum" class="form-control text_xs text-center num" value="@Model.ProNum" />
                            @if (proMulti > 1) {<span style="color:lightseagreen;">退货数量必须是@(proMulti)的倍数</span> }
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>问题描述：</div>
                        <div class="col-md-10 line30">
                            <div>
                                <textarea id="Deailt" name="Deailt" class="form-control" style="width:500px;height:120px;">@Model.Deailt</textarea>
                            </div>
                            <div class="text-right tip_div" style="width:500px;">10-500字</div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right">图片信息：</div>
                        <div class="col-md-10 line30">
                            <div>
                                <input type="button" id="upfile_btn" class="btn btn-info" value="添加图片" />
                                <div style="margin-top: 10px;" id="uploader" class="uploader">
                                    <ul class="filelist"></ul>
                                </div>
                                <input type="hidden" id="Attach_Hid" name="Attach_Hid" value="@(string.IsNullOrEmpty(Model.ProImgs) ? "" : Model.ProImgs.Trim('|'))" />
                            </div>
                            <div>为了帮助我们更好的解决问题，请您上传图片</div>
                            <div class="tip_div">最多可上传5张图片，每张图片大小不超过5M，支持bmp,gif,jpg,png,jpeg格式文件</div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right">申请凭据：</div>
                        <div class="col-md-10 line30">
                            <label><input type="checkbox" value="1" name="cret" /> 有发票</label>
                            <label><input type="checkbox" value="2" name="cret" /> 有检测报告</label>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>返回方式：</div>
                        <div class="col-md-10 line30 typesel_div">
                            <div data-value="1" class="type_div active_div">上门取件</div><div data-value="2" class="type_div">送货到自提点</div>
                            <input type="hidden" id="ReProType_Hid" name="ReProType_Hid" value="@Model.ReProType" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>取货地点：</div>
                        <div class="col-md-10 line30">
                            <div>
                                <select id="province_dp" name="province_dp" class="form-control td_m"></select>
                                <select id="city_dp" name="city_dp" class="form-control td_m"></select>
                                <select id="county_dp" name="county_dp" class="form-control" style="width:92px;"></select>
                                <input type="hidden" id="take_hid" value="@Model.TakeProCounty" />
                            </div>
                            <div class="margin_t5">
                                <input type="text" id="TakeProAddress" name="TakeProAddress" class="form-control text_600" value="@Model.TakeProAddress" placeholder="详细地址" />
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>取件时间：</div>
                        <div class="col-md-10 line30">
                            <input type="text" id="TakeDate_T" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" class="form-control text_300" value="@takedate" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>收货地点：</div>
                        <div class="col-md-10 line30">
                            <div>
                                <select id="reprovince_dp" name="reprovince_dp" class="form-control td_m"></select>
                                <select id="recity_dp" name="recity_dp" class="form-control td_m"></select>
                                <select id="recounty_dp" name="recounty_dp" class="form-control" style="width:92px;"></select>
                                <input type="hidden" id="reurn_hid" value="@Model.ReProCounty" />
                            </div>
                            <div>
                                <input type="text" id="ReProAddress" name="ReProAddress" class="form-control text_600 margin_t5" value="@Model.ReProAddress" placeholder="详细地址" />
                            </div>
                            @*<div><label><input type="checkbox" id="setTakeDate" /> 与取货地址相同</label></div>*@
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>客户姓名：</div>
                        <div class="col-md-10 line30">
                            <input type="text" id="UserName" name="UserName" value="@orderMod.Receiver" class="form-control text_300 notnull" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-2 line30 text-right"><span class="color_red">*</span>手机号码：</div>
                        <div class="col-md-10 line30">
                            <input type="text" id="Phone" name="Phone" class="form-control text_300 phone" value="@Model.Phone" />
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-2 line30"></div>
                        <div class="col-md-10 line30">
                            @if (Model.ID == 0)
                            {
                                <button type="submit" class="btn btn-primary" onclick="return subCheck();">提交信息</button>
                            }
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
}
@section script{
<link href="/JS/Controls/ZL_Webup.css" rel="stylesheet" />
<script src="/JS/Controls/ZL_Dialog.js"></script>
<script src="/JS/DatePicker/WdatePicker.js"></script>
<script src="/JS/Controls/ZL_Webup.js"></script>
<script src="/JS/ZL_Regex.js"></script>
<script>
    $().ready(function () {
        //省市县
        var pcc = new ZL_PCC("province_dp", "city_dp", "county_dp");
        if ($("#take_hid").val() == "") {
            pcc.ProvinceInit();
        }
        else {
            var attr = $("#take_hid").val().split(' ');
            pcc.SetDef(attr[0], attr[1], attr[2]);
            pcc.ProvinceInit();
        }
        var pcc = new ZL_PCC("reprovince_dp", "recity_dp", "recounty_dp");
        if ($("#reurn_hid").val() == "") {
            pcc.ProvinceInit();
        }
        else {
            var attr = $("#reurn_hid").val().split(' ');
            pcc.SetDef(attr[0], attr[1], attr[2]);
            pcc.ProvinceInit();
        }
        //初始化返回方式
        var $types = $("#ReProType_Hid").parent();
        $types.find('.type_div').removeClass('active_div');
        $types.find('[data-value="' + $("#ReProType_Hid").val() + '"]').addClass('active_div');
        //初始化服务类型
        var $services = $("#ServicesType_Hid").parent();
        $services.find('.type_div').removeClass('active_div');
        $services.find('[data-value="' + $("#ServicesType_Hid").val() + '"]').addClass('active_div');
        //初始化图片
        var imgs = $("#Attach_Hid").val();
        if (imgs != "") { ZL_Webup.AddReadOnlyLi(imgs); }
        if (@Model.ID > 0) {
            $(".reqrepair *").attr('disabled', 'disabled');
            return;
        }
        //上传
        ZL_Webup.config.json.ashx = "action=OAattach";
        $("#upfile_btn").click(ZL_Webup.ShowFileUP);

        //返回方式选择
        var $types = $("#ReProType_Hid").parent();
        $types.find('.type_div').click(function () {
            $types.find('.type_div').removeClass('active_div');
            $(this).addClass('active_div');
            $("#ReProType_Hid").val($(this).data('value'));
        });
        //服务类型选择
        var $services = $("#ServicesType_Hid").parent();
        $services.find('.type_div').click(function () {
            $services.find('.type_div').removeClass('active_div');
            $(this).addClass('active_div');
            $("#ServicesType_Hid").val($(this).data('value'));
            console.log("service",$("#ServicesType_Hid").val());
        });
        var present={};
        //----
        $("form").validate({
            rules: {
                ProNum: { required: true, digits: true, range:[1,@cartMod.Pronum] },
                Deailt: { required: true, rangelength:[10,500]},
                TakeDate_T: { required: true },
                UserName: { required: true },
                Phone: { mobile: true }
            },
            messages: {
                ProNum: { required: "提交数量不能为空", digits: "提交数量只能为整数", range:"提交数量必须大于0且小于购买数量" },
                Deailt: { required: "问题描述不能为空" },
                TakeDate_T: { required: "取件时间不能为空" },
                UserName: { required: "客户姓名不能为空" }
            },
        });
    });
    function AddAttach(file, ret, pval) { return ZL_Webup.AddAttach(file, ret, pval); }
    function subCheck()
    {
        var valid = $("form").validate({ meta: "validate" });
        if (!valid.form()) {return false; }
        //是否有促销信息,否则必须满足促销退货条件
        var proMulti=parseInt("@(proMulti)");
        var pronum=Convert.ToInt($("#ProNum").val());
        if(pronum%proMulti!=0){alert("退货数量必须是@(proMulti)的倍数");return false;}
        return true;
    }
</script>
}